
 <!DOCTYPE HTML>
<html lang="ch">
<head>
  <meta charset="UTF-8">
  
    <title>Git使用细节 | Yuan</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="Luo Yuan">
    

    
    <meta name="description" content="Git 是一个免费，开源，分布式源代码管理（版本控制） 系统。本文介绍一些git命令的使用方法，关于git的原理解释就不在此处提及。">
<meta property="og:type" content="article">
<meta property="og:title" content="Git使用细节">
<meta property="og:url" content="http://luoyuan800.github.io/2019/07/03/git-tip/index.html">
<meta property="og:site_name" content="Yuan">
<meta property="og:description" content="Git 是一个免费，开源，分布式源代码管理（版本控制） 系统。本文介绍一些git命令的使用方法，关于git的原理解释就不在此处提及。">
<meta property="og:locale">
<meta property="article:published_time" content="2019-07-03T09:17:14.000Z">
<meta property="article:modified_time" content="2021-04-30T07:58:40.891Z">
<meta property="article:author" content="Luo Yuan">
<meta name="twitter:card" content="summary">

    
    <link rel="alternative" href="/atom.xml" title="Yuan" type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/jacman.jpg">
    
    
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/%02.css">
<link rel="stylesheet" href="/.css">

<meta name="generator" content="Hexo 5.4.0"></head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/logo.png" alt="Yuan" title="Yuan"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="Yuan">Yuan</a></h1>
				<h2 class="blog-motto">一点一滴，积累技术</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/">Home</a></li>
					
						<li><a href="/archives">Archives</a></li>
					
						<li><a href="/about">About</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:luoyuan800.github.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2019/07/03/git-tip/" title="Git使用细节" itemprop="url">Git使用细节</a>
  </h1>
  <p class="article-author">By
       
		<a href="/about" title="Luo Yuan" target="_blank" itemprop="author">Luo Yuan</a>
		
  <p class="article-time">
    <time datetime="2019-07-03T09:17:14.000Z" itemprop="datePublished"> Published 2019-07-03</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Git"><span class="toc-number">1.</span> <span class="toc-text">安装Git</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%9C%AF%E8%AF%AD%E8%A7%A3%E9%87%8A"><span class="toc-number">2.</span> <span class="toc-text">基本术语解释</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Git%E4%BB%93%E5%BA%93-%E4%BB%A3%E7%A0%81%E5%AD%98%E5%82%A8%E7%9A%84%E5%9C%B0%E6%96%B9"><span class="toc-number">2.1.</span> <span class="toc-text">Git仓库 - 代码存储的地方</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93"><span class="toc-number">2.1.1.</span> <span class="toc-text">本地仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%EF%BC%88origin%EF%BC%89"><span class="toc-number">2.1.2.</span> <span class="toc-text">远程仓库（origin）</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF%EF%BC%88Branch%EF%BC%89"><span class="toc-number">2.2.</span> <span class="toc-text">分支（Branch）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HEAD"><span class="toc-number">2.3.</span> <span class="toc-text">HEAD</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%90%E4%BA%A4%E4%BF%AE%E6%94%B9%EF%BC%88Commit%EF%BC%89"><span class="toc-number">2.4.</span> <span class="toc-text">提交修改（Commit）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%EF%BC%88Push%EF%BC%89"><span class="toc-number">2.5.</span> <span class="toc-text">推送（Push）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8B%89%E5%8F%96%EF%BC%88Pull%EF%BC%89"><span class="toc-number">2.6.</span> <span class="toc-text">拉取（Pull）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Checkout"><span class="toc-number">2.7.</span> <span class="toc-text">Checkout</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6%EF%BC%88Clone%EF%BC%89%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%88%B0%E6%9C%AC%E5%9C%B0"><span class="toc-number">3.</span> <span class="toc-text">复制（Clone）远程代码到本地</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E6%9C%AC%E5%9C%B0%E7%9A%84%E6%96%87%E4%BB%B6%E4%BF%AE%E6%94%B9"><span class="toc-number">4.</span> <span class="toc-text">撤销本地的文件修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8%E6%9F%90%E4%B8%AA%E5%88%86%E6%94%AF%E7%9A%84%E5%9F%BA%E7%A1%80%E4%B8%8A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E5%88%86%E6%94%AF%EF%BC%88%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93%EF%BC%89"><span class="toc-number">5.</span> <span class="toc-text">在某个分支的基础上创建一个新的分支（本地仓库）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%A8%E6%8C%87%E5%AE%9A%E7%9A%84%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF%E6%9B%B4%E6%96%B0%E5%BD%93%E5%89%8D%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">6.</span> <span class="toc-text">用指定的远程分支更新当前的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B3%E8%81%94%E5%BD%93%E5%89%8D%E7%9A%84%E5%88%86%E6%94%AF%E5%92%8C%E8%BF%9C%E7%A8%8B%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">7.</span> <span class="toc-text">关联当前的分支和远程的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E5%BD%93%E5%89%8D%E9%A1%B9%E7%9B%AE%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BD%9C%E8%80%85%E5%90%8D%E7%A7%B0"><span class="toc-number">8.</span> <span class="toc-text">修改当前项目提交（commit）的作者名称</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E4%B8%8A%E4%B8%80%E6%AC%A1%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BD%9C%E8%80%85"><span class="toc-number">9.</span> <span class="toc-text">修改上一次提交（commit）的作者</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%8C%87%E5%AE%9A%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BF%A1%E6%81%AF%EF%BC%88%E4%BD%9C%E8%80%85%E6%88%96%E8%80%85%E6%B3%A8%E9%87%8A%E4%BF%A1%E6%81%AF%EF%BC%89"><span class="toc-number">10.</span> <span class="toc-text">修改指定提交（commit）的信息（作者或者注释信息）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E8%AE%B0%E5%BD%95%EF%BC%9A"><span class="toc-number">11.</span> <span class="toc-text">查看提交（commit）的记录：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E4%B8%8A%E4%B8%80%E6%AC%A1%E6%8F%90%E4%BA%A4%EF%BC%88Commit%EF%BC%89"><span class="toc-number">12.</span> <span class="toc-text">撤销上一次提交（Commit）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E4%B8%8A%E4%B8%80%E6%AC%A1%E5%B7%B2%E7%BB%8F%E6%8E%A8%E9%80%81%EF%BC%88push%EF%BC%89%E4%B8%8A%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E6%8F%90%E4%BA%A4"><span class="toc-number">13.</span> <span class="toc-text">撤销上一次已经推送（push）上远程仓库的提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Merge%E6%93%8D%E4%BD%9C"><span class="toc-number">14.</span> <span class="toc-text">Merge操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%EF%BC%88Merge%EF%BC%89"><span class="toc-number">14.1.</span> <span class="toc-text">合并（Merge）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Cherry"><span class="toc-number">14.2.</span> <span class="toc-text">Cherry</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%B2%E7%AA%81"><span class="toc-number">15.</span> <span class="toc-text">冲突</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%BA%E5%88%B6%E8%A6%86%E7%9B%96%E6%9C%AC%E5%9C%B0%E6%96%87%E4%BB%B6"><span class="toc-number">16.</span> <span class="toc-text">强制覆盖本地文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%B2%A1%E6%9C%89%E5%8A%A0%E5%85%A5%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%EF%BC%88untrak%EF%BC%89%E7%9A%84%E6%96%87%E4%BB%B6"><span class="toc-number">17.</span> <span class="toc-text">删除没有加入版本控制（untrak）的文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E4%BA%AB%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93"><span class="toc-number">18.</span> <span class="toc-text">分享本地仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%A0%87%E7%AD%BE%EF%BC%88Tag%EF%BC%89"><span class="toc-number">19.</span> <span class="toc-text">创建标签（Tag）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%E5%B8%A6%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">20.</span> <span class="toc-text">推送带特殊字符的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3EOF%E9%94%99%E8%AF%AF"><span class="toc-number">21.</span> <span class="toc-text">解决EOF错误</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BD%9C%E8%80%85%E4%BF%A1%E6%81%AF"><span class="toc-number">22.</span> <span class="toc-text">修改提交（commit）的作者信息</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E5%9C%B0%E5%9D%80"><span class="toc-number">23.</span> <span class="toc-text">修改远程仓库的地址</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HTTP%E4%BB%93%E5%BA%93%E5%9C%B0%E5%9D%80%E4%B8%AD%E5%8A%A0%E5%85%A5%E7%94%A8%E6%88%B7%E5%90%8D%E5%92%8C%E5%AF%86%E7%A0%81"><span class="toc-number">24.</span> <span class="toc-text">HTTP仓库地址中加入用户名和密码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96%EF%BC%8C%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0%E5%BC%BA%E8%A1%8C%E6%8F%90%E4%BA%A4-f"><span class="toc-number">25.</span> <span class="toc-text">分支覆盖，需要用到强行提交 -f</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git-%E6%9F%A5%E7%9C%8B%E9%85%8D%E7%BD%AE"><span class="toc-number">26.</span> <span class="toc-text">Git 查看配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git-%E5%B8%90%E5%8F%B7%E5%90%8D%E5%AF%86%E7%A0%81%E4%BF%9D%E6%8C%81"><span class="toc-number">27.</span> <span class="toc-text">Git 帐号名密码保持</span></a></li></ol>
		
		</div>
		
		<p>Git 是一个免费，开源，分布式源代码管理（版本控制） 系统。本文介绍一些git命令的使用方法，关于git的原理解释就不在此处提及。<span id="more"></span></p>
<h2 id="安装Git"><a href="#安装Git" class="headerlink" title="安装Git"></a>安装Git</h2><p>打开<a target="_blank" rel="noopener" href="https://git-scm.com/%E7%BD%91%E7%AB%99%EF%BC%8C%E9%80%89%E6%8B%A9%E7%B3%BB%E7%BB%9F%E5%AF%B9%E5%BA%94%E7%89%88%E6%9C%AC%E7%9A%84Git%E5%AE%89%E8%A3%85%E5%8C%85%E4%B8%8B%E8%BD%BD%E5%90%8E%E5%AE%89%E8%A3%85%E5%8D%B3%E5%8F%AF%E3%80%82">https://git-scm.com/网站，选择系统对应版本的Git安装包下载后安装即可。</a></p>
<h2 id="基本术语解释"><a href="#基本术语解释" class="headerlink" title="基本术语解释"></a>基本术语解释</h2><h3 id="Git仓库-代码存储的地方"><a href="#Git仓库-代码存储的地方" class="headerlink" title="Git仓库 - 代码存储的地方"></a>Git仓库 - 代码存储的地方</h3><h4 id="本地仓库"><a href="#本地仓库" class="headerlink" title="本地仓库"></a>本地仓库</h4><p>顾名思义是在你自己本地机器上保存（commit）的代码版本控制信息。</p>
<h4 id="远程仓库（origin）"><a href="#远程仓库（origin）" class="headerlink" title="远程仓库（origin）"></a>远程仓库（origin）</h4><p>一个网络上的共享仓库（比如说你在Github上创建一的项目，这个项目地址就是一个共享仓库），本地仓库的代码信息推送（push）到远程仓库上之后，别的开发者就可以拉取（pull）到他们了。</p>
<h3 id="分支（Branch）"><a href="#分支（Branch）" class="headerlink" title="分支（Branch）"></a>分支（Branch）</h3><p>Git是通过链表的模式存储代码的每一次提交信息的，分支就是指向这个链表某一个节点的指针。我们可以创建多个分支，然后在这个分支上的提交就会分出一个新的链表。</p>
<h3 id="HEAD"><a href="#HEAD" class="headerlink" title="HEAD"></a>HEAD</h3><p>和分支一起使用，HEAD始终指向当前分支的最新的提交点。</p>
<h3 id="提交修改（Commit）"><a href="#提交修改（Commit）" class="headerlink" title="提交修改（Commit）"></a>提交修改（Commit）</h3><p>提交修改只是在当前分支创建一个新的节点，这个提交包含代码的变动，并且包含提交的信息和相关的注释（比如修改了什么）。提交只是把代码修改信息保存在本地仓库。</p>
<h3 id="推送（Push）"><a href="#推送（Push）" class="headerlink" title="推送（Push）"></a>推送（Push）</h3><p>Push是将本地仓库保持的代码修改信息同步到远程仓库上。</p>
<h3 id="拉取（Pull）"><a href="#拉取（Pull）" class="headerlink" title="拉取（Pull）"></a>拉取（Pull）</h3><p>拉取(pull)一个分支意味着把它相关的代码提交（Commit）抓取(fetch)下来并合并(merge)到当前的分支中。</p>
<h3 id="Checkout"><a href="#Checkout" class="headerlink" title="Checkout"></a>Checkout</h3><p>修改当前的工作分支为另外一个分支。</p>
<h2 id="复制（Clone）远程代码到本地"><a href="#复制（Clone）远程代码到本地" class="headerlink" title="复制（Clone）远程代码到本地"></a>复制（Clone）远程代码到本地</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">clone</span> &lt;版本库网址&gt;  &lt;本地文件夹&gt; <span class="comment">## 这个命令是默认建立master分支</span></span><br></pre></td></tr></table></figure>
<p>在clone出master分支之后，在对应的master文件夹下面使用checkout命令可以下载分支的代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout -b branch origin/branch  <span class="comment">## 这个命令会在当前目录下载指定分支</span></span><br></pre></td></tr></table></figure>
<p>如果只需要一个branch的代码，可以考虑直接clone一个branch的代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">clone</span> -b &lt;branch name&gt; &lt;版本库网址&gt; &lt;本地文件夹位置（可选）&gt; <span class="comment">## 这个命令可以clone对应的branch代码并且放到指定的文件夹中</span></span><br></pre></td></tr></table></figure>

<h2 id="撤销本地的文件修改"><a href="#撤销本地的文件修改" class="headerlink" title="撤销本地的文件修改"></a>撤销本地的文件修改</h2><p>使用远程版本库的文件覆盖本地的文件，其本质是将本地版本库的文件头回退，即是使得git记录文件修改的文件忘记本次修改的内容，然后是用pull更新当前代码。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git reset --hard</span><br><span class="line">$ git pull</span><br></pre></td></tr></table></figure>

<h2 id="在某个分支的基础上创建一个新的分支（本地仓库）"><a href="#在某个分支的基础上创建一个新的分支（本地仓库）" class="headerlink" title="在某个分支的基础上创建一个新的分支（本地仓库）"></a>在某个分支的基础上创建一个新的分支（本地仓库）</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout -b &lt;新分支名字&gt; origin/&lt;远程分支名&gt; <span class="comment">## 这个命令只会在本地仓库创建一个新的分支，需要执行提交（commit）和推送（ push）命令后才会在远程仓库创建。</span></span><br></pre></td></tr></table></figure>

<h2 id="用指定的远程分支更新当前的分支"><a href="#用指定的远程分支更新当前的分支" class="headerlink" title="用指定的远程分支更新当前的分支"></a>用指定的远程分支更新当前的分支</h2><p>这个命令要在需要更新分支的文件目录下执行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git pull origin &lt;远程仓库上的分支名&gt;</span><br></pre></td></tr></table></figure>

<h2 id="关联当前的分支和远程的分支"><a href="#关联当前的分支和远程的分支" class="headerlink" title="关联当前的分支和远程的分支"></a>关联当前的分支和远程的分支</h2><p>这个命令可以指定当前本地的分支的拉取操作（pull）和推送操作（push）的远程仓库对应的分支是哪一个（如果是直接从远程分支checkout的分支就默认关联同名）</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git bran -- set-upstram &lt;localBranch&gt; origin/&lt;remoteBranch&gt;</span><br></pre></td></tr></table></figure>

<h2 id="修改当前项目提交（commit）的作者名称"><a href="#修改当前项目提交（commit）的作者名称" class="headerlink" title="修改当前项目提交（commit）的作者名称"></a>修改当前项目提交（commit）的作者名称</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git config user.name &lt;name&gt; <span class="comment">## 修改用户名称</span></span><br><span class="line">$ git config user.email &lt;emailmail@xxx.com&gt; <span class="comment">## 修改提交（commit）的作者的email</span></span><br></pre></td></tr></table></figure>
<p>以上的两个步骤也可以打开.git文件目录下的config文件，修改里面的author和email。修改完成之后下一次提交（commit）就会适应这个新的配置了。</p>
<h2 id="修改上一次提交（commit）的作者"><a href="#修改上一次提交（commit）的作者" class="headerlink" title="修改上一次提交（commit）的作者"></a>修改上一次提交（commit）的作者</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git commit --amend --author=<span class="string">&#x27;Gavin Luo &lt;emailmail@main.com&gt;&#x27;</span></span><br></pre></td></tr></table></figure>

<h2 id="修改指定提交（commit）的信息（作者或者注释信息）"><a href="#修改指定提交（commit）的信息（作者或者注释信息）" class="headerlink" title="修改指定提交（commit）的信息（作者或者注释信息）"></a>修改指定提交（commit）的信息（作者或者注释信息）</h2><p>首先用以下命令进入编辑模式</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git  rebase --interactive  commi_id^</span><br></pre></td></tr></table></figure>
<p>然后在出现的编辑窗口（vim编辑器类似：i进入编辑模式，esc结束编辑进入命令模式，:w保存修改，:q退出）将要要修改的提交（commit）前面的<code>pick</code>改成<code>edit</code>。然后执行命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git  commit  --amend</span><br></pre></td></tr></table></figure>
<p>在出现的界面中填写相关信息后使用以下命令提交修改</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git rebase --<span class="built_in">continue</span></span><br><span class="line">git push --rebase</span><br></pre></td></tr></table></figure>

<h2 id="查看提交（commit）的记录："><a href="#查看提交（commit）的记录：" class="headerlink" title="查看提交（commit）的记录："></a>查看提交（commit）的记录：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">log</span></span><br></pre></td></tr></table></figure>

<h2 id="撤销上一次提交（Commit）"><a href="#撤销上一次提交（Commit）" class="headerlink" title="撤销上一次提交（Commit）"></a>撤销上一次提交（Commit）</h2><p>如果在提交之前忘记拉取（pull）最新的代码下来会导致无法推送（push）本地修改的代码到远程，这个时候可以先撤销上一次的提交，更新本地代码之后再从那时提交一次就可以了。<br>重置（reset）命令是可以撤销本地的提交，不过要记得重置（reset）之后要拉取（pull）一下，把远程的更新拉到本地。注意这个命令不会产生新的提交（commit）。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git reset HEAD~1</span><br><span class="line">$ git pull</span><br></pre></td></tr></table></figure>

<h2 id="撤销上一次已经推送（push）上远程仓库的提交"><a href="#撤销上一次已经推送（push）上远程仓库的提交" class="headerlink" title="撤销上一次已经推送（push）上远程仓库的提交"></a>撤销上一次已经推送（push）上远程仓库的提交</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git revert HEAD</span><br><span class="line">$ git push</span><br></pre></td></tr></table></figure>
<p>这个命令会产生一个新的提交（commit）。</p>
<h2 id="Merge操作"><a href="#Merge操作" class="headerlink" title="Merge操作"></a>Merge操作</h2><h3 id="合并（Merge）"><a href="#合并（Merge）" class="headerlink" title="合并（Merge）"></a>合并（Merge）</h3><p>合并是将一个分支的修改内容合并到另外一个分支。首先切换（checkout）到要进行合并（merge）的分支（branch）目录下，然后指定要合并进来的另外一个分支的名字。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout localbranch</span><br><span class="line">$ git merge origin/remotebranch</span><br><span class="line"><span class="comment">## remotebranch的修改会合并到当前的localbranch中</span></span><br></pre></td></tr></table></figure>

<h3 id="Cherry"><a href="#Cherry" class="headerlink" title="Cherry"></a>Cherry</h3><p>Cherry 命令可以挑选一个分支上的某些提交（commit）合并到当前分支上。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout localbranch</span><br><span class="line">$ git cherry-pick 12345 <span class="comment">##12345为commit id</span></span><br></pre></td></tr></table></figure>
<p>如果是要同时挑选多个提交（commit）可以使用-n</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout localbranch</span><br><span class="line">$ git cherry-pick -n 12345 <span class="comment">##12345为commit id</span></span><br><span class="line">$ git cherry-pick -n 13333 <span class="comment">##1333为commit id</span></span><br><span class="line">$ git commit -m <span class="string">&quot;cherry test&quot;</span></span><br></pre></td></tr></table></figure>
<h2 id="冲突"><a href="#冲突" class="headerlink" title="冲突"></a>冲突</h2><p>执行会导致合并的相关命令（merge、cherry）后如果没有冲突，那么合并对象分支的修改就会合并到当前的分支中了。如果发生了冲突，就需要先打开文件解决冲突，然后把修改好的冲突文件重新添加（add）之后再提交（commit）一次。</p>
<h2 id="强制覆盖本地文件"><a href="#强制覆盖本地文件" class="headerlink" title="强制覆盖本地文件"></a>强制覆盖本地文件</h2><p>相信很多人都很烦恼合并（merge）的问题，如果发生了很蛋疼的冲突（难于修复），可以直接用服务器上代码更新本地的代码，但是本地修改就会丢失。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git fetch --all</span><br><span class="line">$ git reset --hard</span><br><span class="line">$ git pull</span><br></pre></td></tr></table></figure>

<h2 id="删除没有加入版本控制（untrak）的文件"><a href="#删除没有加入版本控制（untrak）的文件" class="headerlink" title="删除没有加入版本控制（untrak）的文件"></a>删除没有加入版本控制（untrak）的文件</h2><p>不小心批量添加了文件，在没有提交之前可以一次性全部删除</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git clean -f  <span class="comment">## 删除 untracked files</span></span><br><span class="line">$ git clean -fd <span class="comment">## 删除文件的同时也会删除文件夹</span></span><br><span class="line">$ git clean -xfd <span class="comment">## gitignore 的也会被删除</span></span><br></pre></td></tr></table></figure>

<p>在命令前加上-n可以查看会被删除掉的文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git clean -nxfd</span><br></pre></td></tr></table></figure>

<h2 id="分享本地仓库"><a href="#分享本地仓库" class="headerlink" title="分享本地仓库"></a>分享本地仓库</h2><p>当你从远程仓库拷贝（clone）代码之后，你本地其实也同时建立了一个完整的仓库。你可以将这个仓库作为团队开发时的共享仓库<br>在windows系统下，你只需要共享你的项目文件夹，然后让其他组员通过<code>git clone file:///$你的共享项目路径</code>就可以了。<br>如果其他组员也下载了远程仓库的代码，那么可以让他们修改.git文件夹内的config文件，将其中的[remote “origin”]下的ulr地址改成你的共享文件夹目录就可以了，记得加上<code>file:///</code>，并且在你的共享地址前面加上<code>\</code>进行转义，所以url的值应该看起来是这样的：<br><code>file:///\\hostname\file_path</code>。<br>当你共享了自己的仓库给其他用户之后，记得开启写权限给他们。<br>还有一个一定要注意的问题，如果你和你组员都需要提交到同样的branch，那么你不能占用那个branch，你必须也重新建立一个branch来进行你的工作。否则，如果其他人要提交的branch在你的工作环境中是check out的状态的话，别人提交会有 unpacker err。</p>
<h2 id="创建标签（Tag）"><a href="#创建标签（Tag）" class="headerlink" title="创建标签（Tag）"></a>创建标签（Tag）</h2><p>标签通常是用来标识提交链表(commit ancerstry chain)中的某一点，他和提交（commit）信息绑定在一起。</p>
<ol>
<li><code>git tag &lt;tagename&gt;</code>。 这个命令是给当前的提交（commit）打上一个轻量级的标签（tag）。</li>
<li><code>git tag -a &lt;tagename&gt; -m &lt;tagmessage&gt;</code> 。这个命令是个当前提交（commit）打上一个带有备注的标签（tag）。</li>
<li><code>git push origin &lt;tagename&gt;</code> 发布标签（tag）到远程仓库</li>
<li><code>git push origin --tags</code> 发布所有的本地标签（tag）到远程仓库。</li>
</ol>
<h2 id="推送带特殊字符的分支"><a href="#推送带特殊字符的分支" class="headerlink" title="推送带特殊字符的分支"></a>推送带特殊字符的分支</h2><p>需要用反斜杠进行转义</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push origin HEAD:bugfix&#x2F;XXX</span><br></pre></td></tr></table></figure>
<h2 id="解决EOF错误"><a href="#解决EOF错误" class="headerlink" title="解决EOF错误"></a>解决EOF错误</h2><dl><dt>fatal: The remote end hung up unexpectfataledly | 12.00 KiB/s</dt><dd>early EOF<br>fatal: index-pack failed</dd></dl><p>这个错误是读取远程仓库的时候丢失数据或者数据损坏导致的。解决方法是加大缓存： git config –global http.postBuffer 104857600</p>
<h2 id="修改提交（commit）的作者信息"><a href="#修改提交（commit）的作者信息" class="headerlink" title="修改提交（commit）的作者信息"></a>修改提交（commit）的作者信息</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line">git filter-branch --env-filter <span class="string">&#x27;</span></span><br><span class="line"><span class="string">OLD_EMAIL=&quot;luoyuan800@163.com&quot;</span></span><br><span class="line"><span class="string">CORRECT_NAME=&quot;Gavin Luo&quot;</span></span><br><span class="line"><span class="string">CORRECT_EMAIL=&quot;Gavin.luo@quest.com&quot;</span></span><br><span class="line"><span class="string">if [ &quot;$GIT_COMMITTER_EMAIL&quot; = &quot;$OLD_EMAIL&quot; ]</span></span><br><span class="line"><span class="string">then</span></span><br><span class="line"><span class="string">    export GIT_COMMITTER_NAME=&quot;$CORRECT_NAME&quot;</span></span><br><span class="line"><span class="string">    export GIT_COMMITTER_EMAIL=&quot;$CORRECT_EMAIL&quot;</span></span><br><span class="line"><span class="string">fi</span></span><br><span class="line"><span class="string">if [ &quot;$GIT_AUTHOR_EMAIL&quot; = &quot;$OLD_EMAIL&quot; ]</span></span><br><span class="line"><span class="string">then</span></span><br><span class="line"><span class="string">    export GIT_AUTHOR_NAME=&quot;$CORRECT_NAME&quot;</span></span><br><span class="line"><span class="string">    export GIT_AUTHOR_EMAIL=&quot;$CORRECT_EMAIL&quot;</span></span><br><span class="line"><span class="string">fi</span></span><br><span class="line"><span class="string">&#x27;</span> --tag-name-filter cat -- --branches --tags</span><br></pre></td></tr></table></figure>
<p>之后要使用 <code>git push --force --tags origin &#39;refs/heads/*&#39;</code> 强制覆盖提交<br>参考：<a target="_blank" rel="noopener" href="https://www.hidennis.tech/2016/06/07/git-change-author-email/">https://www.hidennis.tech/2016/06/07/git-change-author-email/</a></p>
<h2 id="修改远程仓库的地址"><a href="#修改远程仓库的地址" class="headerlink" title="修改远程仓库的地址"></a>修改远程仓库的地址</h2><p>一个git项目可以有多个仓库， 可以使用命令<code>git remote</code> 列出所有的远程仓库； 使用<code>git remote get-url &lt;仓库名, 比如origin&gt;</code>显示仓库地址。</p>
<p>使用<code>git remote set-url origin &lt;url_path&gt;</code> 来设置指定的仓库地址</p>
<h2 id="HTTP仓库地址中加入用户名和密码"><a href="#HTTP仓库地址中加入用户名和密码" class="headerlink" title="HTTP仓库地址中加入用户名和密码"></a>HTTP仓库地址中加入用户名和密码</h2><p>格式为<code>https://username:passwoard@git.address</code>。如果username或者password中包含有特殊字符需要进行转义。 常见的特殊字符为 <code>:</code> : <code>%3A</code>；<code>@</code> : <code>%40</code> ；<code> (空隔)</code>:<code>%20</code>。其他特殊字符可以自行网上查找</p>
<h2 id="分支覆盖，需要用到强行提交-f"><a href="#分支覆盖，需要用到强行提交-f" class="headerlink" title="分支覆盖，需要用到强行提交 -f"></a>分支覆盖，需要用到强行提交 -f</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard origin&#x2F;branch</span><br><span class="line">git push -f</span><br></pre></td></tr></table></figure>

<h2 id="Git-查看配置"><a href="#Git-查看配置" class="headerlink" title="Git 查看配置"></a>Git 查看配置</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config user.name ##查看用户名</span><br><span class="line">git config user.email ##查看邮箱</span><br></pre></td></tr></table></figure>

<h2 id="Git-帐号名密码保持"><a href="#Git-帐号名密码保持" class="headerlink" title="Git 帐号名密码保持"></a>Git 帐号名密码保持</h2><p>账户名密码会保存到windows credential里面，如果不小心输错了可能会导致之后一直用这个错误，可以打开控制面板然后修改。</p>
  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/%E7%BC%96%E7%A8%8B-%E5%B7%A5%E5%85%B7/">编程-工具</a>
</div>


</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://luoyuan800.github.io/2019/07/03/git-tip/" data-title="Git使用细节 | Yuan" data-tsina="" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2020/01/03/lucene/" title="Lucene：关键字检索">
  <strong>上一篇：</strong><br/>
  <span>
  Lucene：关键字检索</span>
</a>
</div>


<div class="next">
<a href="/2018/10/14/groovy-unique/"  title="Groovy Unique 方法性能测试">
 <strong>下一篇：</strong><br/> 
 <span>Groovy Unique 方法性能测试
</span>
</a>
</div>

</nav>

	



</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Git"><span class="toc-number">1.</span> <span class="toc-text">安装Git</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%9C%AF%E8%AF%AD%E8%A7%A3%E9%87%8A"><span class="toc-number">2.</span> <span class="toc-text">基本术语解释</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Git%E4%BB%93%E5%BA%93-%E4%BB%A3%E7%A0%81%E5%AD%98%E5%82%A8%E7%9A%84%E5%9C%B0%E6%96%B9"><span class="toc-number">2.1.</span> <span class="toc-text">Git仓库 - 代码存储的地方</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93"><span class="toc-number">2.1.1.</span> <span class="toc-text">本地仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%EF%BC%88origin%EF%BC%89"><span class="toc-number">2.1.2.</span> <span class="toc-text">远程仓库（origin）</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF%EF%BC%88Branch%EF%BC%89"><span class="toc-number">2.2.</span> <span class="toc-text">分支（Branch）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HEAD"><span class="toc-number">2.3.</span> <span class="toc-text">HEAD</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%90%E4%BA%A4%E4%BF%AE%E6%94%B9%EF%BC%88Commit%EF%BC%89"><span class="toc-number">2.4.</span> <span class="toc-text">提交修改（Commit）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%EF%BC%88Push%EF%BC%89"><span class="toc-number">2.5.</span> <span class="toc-text">推送（Push）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8B%89%E5%8F%96%EF%BC%88Pull%EF%BC%89"><span class="toc-number">2.6.</span> <span class="toc-text">拉取（Pull）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Checkout"><span class="toc-number">2.7.</span> <span class="toc-text">Checkout</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6%EF%BC%88Clone%EF%BC%89%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81%E5%88%B0%E6%9C%AC%E5%9C%B0"><span class="toc-number">3.</span> <span class="toc-text">复制（Clone）远程代码到本地</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E6%9C%AC%E5%9C%B0%E7%9A%84%E6%96%87%E4%BB%B6%E4%BF%AE%E6%94%B9"><span class="toc-number">4.</span> <span class="toc-text">撤销本地的文件修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8%E6%9F%90%E4%B8%AA%E5%88%86%E6%94%AF%E7%9A%84%E5%9F%BA%E7%A1%80%E4%B8%8A%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E5%88%86%E6%94%AF%EF%BC%88%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93%EF%BC%89"><span class="toc-number">5.</span> <span class="toc-text">在某个分支的基础上创建一个新的分支（本地仓库）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%94%A8%E6%8C%87%E5%AE%9A%E7%9A%84%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF%E6%9B%B4%E6%96%B0%E5%BD%93%E5%89%8D%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">6.</span> <span class="toc-text">用指定的远程分支更新当前的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B3%E8%81%94%E5%BD%93%E5%89%8D%E7%9A%84%E5%88%86%E6%94%AF%E5%92%8C%E8%BF%9C%E7%A8%8B%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">7.</span> <span class="toc-text">关联当前的分支和远程的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E5%BD%93%E5%89%8D%E9%A1%B9%E7%9B%AE%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BD%9C%E8%80%85%E5%90%8D%E7%A7%B0"><span class="toc-number">8.</span> <span class="toc-text">修改当前项目提交（commit）的作者名称</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E4%B8%8A%E4%B8%80%E6%AC%A1%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BD%9C%E8%80%85"><span class="toc-number">9.</span> <span class="toc-text">修改上一次提交（commit）的作者</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%8C%87%E5%AE%9A%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BF%A1%E6%81%AF%EF%BC%88%E4%BD%9C%E8%80%85%E6%88%96%E8%80%85%E6%B3%A8%E9%87%8A%E4%BF%A1%E6%81%AF%EF%BC%89"><span class="toc-number">10.</span> <span class="toc-text">修改指定提交（commit）的信息（作者或者注释信息）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E8%AE%B0%E5%BD%95%EF%BC%9A"><span class="toc-number">11.</span> <span class="toc-text">查看提交（commit）的记录：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E4%B8%8A%E4%B8%80%E6%AC%A1%E6%8F%90%E4%BA%A4%EF%BC%88Commit%EF%BC%89"><span class="toc-number">12.</span> <span class="toc-text">撤销上一次提交（Commit）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E4%B8%8A%E4%B8%80%E6%AC%A1%E5%B7%B2%E7%BB%8F%E6%8E%A8%E9%80%81%EF%BC%88push%EF%BC%89%E4%B8%8A%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E6%8F%90%E4%BA%A4"><span class="toc-number">13.</span> <span class="toc-text">撤销上一次已经推送（push）上远程仓库的提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Merge%E6%93%8D%E4%BD%9C"><span class="toc-number">14.</span> <span class="toc-text">Merge操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%EF%BC%88Merge%EF%BC%89"><span class="toc-number">14.1.</span> <span class="toc-text">合并（Merge）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Cherry"><span class="toc-number">14.2.</span> <span class="toc-text">Cherry</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%86%B2%E7%AA%81"><span class="toc-number">15.</span> <span class="toc-text">冲突</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%BA%E5%88%B6%E8%A6%86%E7%9B%96%E6%9C%AC%E5%9C%B0%E6%96%87%E4%BB%B6"><span class="toc-number">16.</span> <span class="toc-text">强制覆盖本地文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%B2%A1%E6%9C%89%E5%8A%A0%E5%85%A5%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%EF%BC%88untrak%EF%BC%89%E7%9A%84%E6%96%87%E4%BB%B6"><span class="toc-number">17.</span> <span class="toc-text">删除没有加入版本控制（untrak）的文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E4%BA%AB%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93"><span class="toc-number">18.</span> <span class="toc-text">分享本地仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%A0%87%E7%AD%BE%EF%BC%88Tag%EF%BC%89"><span class="toc-number">19.</span> <span class="toc-text">创建标签（Tag）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A8%E9%80%81%E5%B8%A6%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">20.</span> <span class="toc-text">推送带特殊字符的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3EOF%E9%94%99%E8%AF%AF"><span class="toc-number">21.</span> <span class="toc-text">解决EOF错误</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%8F%90%E4%BA%A4%EF%BC%88commit%EF%BC%89%E7%9A%84%E4%BD%9C%E8%80%85%E4%BF%A1%E6%81%AF"><span class="toc-number">22.</span> <span class="toc-text">修改提交（commit）的作者信息</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E5%9C%B0%E5%9D%80"><span class="toc-number">23.</span> <span class="toc-text">修改远程仓库的地址</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HTTP%E4%BB%93%E5%BA%93%E5%9C%B0%E5%9D%80%E4%B8%AD%E5%8A%A0%E5%85%A5%E7%94%A8%E6%88%B7%E5%90%8D%E5%92%8C%E5%AF%86%E7%A0%81"><span class="toc-number">24.</span> <span class="toc-text">HTTP仓库地址中加入用户名和密码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E8%A6%86%E7%9B%96%EF%BC%8C%E9%9C%80%E8%A6%81%E7%94%A8%E5%88%B0%E5%BC%BA%E8%A1%8C%E6%8F%90%E4%BA%A4-f"><span class="toc-number">25.</span> <span class="toc-text">分支覆盖，需要用到强行提交 -f</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git-%E6%9F%A5%E7%9C%8B%E9%85%8D%E7%BD%AE"><span class="toc-number">26.</span> <span class="toc-text">Git 查看配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Git-%E5%B8%90%E5%8F%B7%E5%90%8D%E5%AF%86%E7%A0%81%E4%BF%9D%E6%8C%81"><span class="toc-number">27.</span> <span class="toc-text">Git 帐号名密码保持</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/categories/杂物-医学/" title="杂物-医学">杂物-医学<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-Java/" title="编程-Java">编程-Java<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-Linux-Unix/" title="编程-Linux/Unix">编程-Linux/Unix<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-工具/" title="编程-工具">编程-工具<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-网络协议/" title="编程-网络协议">编程-网络协议<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/categories/网站-开发/" title="网站-开发">网站-开发<sup>2</sup></a></li>
		  
		
		</ul>
</div>


  

  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=&verifier=&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m Luo Yuan in Zhuhai. <br/>
			Here is my place for knowledge accumulation.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2021 
		
		<a href="/about" target="_blank" title="Luo Yuan">Luo Yuan</a>
		
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>
<script src="/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>











<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/img/scrollup.png"/></a>
	</div>
	<script src="/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
